const LearningContent = require('../modules/learningcontent');

class LearningContentController{

    // static async index(ctx) {
    //     try {
    //         const data = {}
    //         data.learnContentList = await new LearningContent().listALl()
    //         await ctx.render('teachmaterial/index', data)
    //     } catch(err) {
    //         await ctx.render('error', {message: err.message})
    //     }
    // }

    static async detail(ctx) {
        try {
            const id = ctx.params.id
            let data = {}
            let lc = await new LearningContent()
            let res = await lc.getOne(id)
            data.res = res
            let previousContent = await lc.priviousContent(res.teachmaterial_id, id)
            let nextContent = await lc.nextContent(res.teachmaterial_id, id)
            data.teachmaterial_id = res.teachmaterial_id
            if (previousContent) {
                data.pid = previousContent.id
            }
            if (nextContent) {
                data.nid = nextContent.id
            }
            await ctx.render('learningcontent/detail', data)
        } catch(err) {
            await ctx.render('error', {message: err.message})
        }
    }
    
}

exports = module.exports = LearningContentController;